package com.qfedu.fmmall.controller;

import com.qfedu.fmmall.entity.ProductVO;
import com.qfedu.fmmall.service.IndexCategoryService;
import com.qfedu.fmmall.service.IndexImgService;
import com.qfedu.fmmall.service.ProductService;
import com.qfedu.fmmall.vo.ResStatus;
import com.qfedu.fmmall.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liuyadi
 */
@RestController
@RequestMapping("/index")
@Api(value = "提供首页数据显示的接口", tags = "首页管理")
@CrossOrigin
public class IndexController {

    /**
     * 基于构造函数进行注入
     **/
    private final IndexImgService indexImgService;
    private final IndexCategoryService indexCategoryService;
    private final ProductService productService;

    /**
     * 基于构造函数注入
     *
     * @param indexImgService      indexImgService变量
     * @param indexCategoryService indexCategoryService变量
     */
    public IndexController(IndexImgService indexImgService, IndexCategoryService indexCategoryService, ProductService productService) {
        this.indexCategoryService = indexCategoryService;
        this.indexImgService = indexImgService;
        this.productService = productService;
    }

    /**
     * 轮播图查询接口
     *
     * @return ResultVO
     */
    @ApiOperation(value = "轮播图查询接口")
    @GetMapping("/indexImg")
    public ResultVO queryIndexImg() {
        return indexImgService.queryIndexImgs();
    }

    /**
     * 首页分类连接查询接口
     *
     * @return ResultVO
     */
    @ApiOperation(value = "首页分类连接查询接口")
    @GetMapping("/indexCategory")
    public ResultVO queryCategory() {
        return indexCategoryService.queryCategory();
    }

    /**
     * 首页分类子查询接口
     *
     * @param parentId 父级分类id
     * @return ResultVO
     */
    @ApiOperation(value = "首页分类子查询接口")
    @ApiImplicitParam(dataType = "Integer", value = "父类id", name = "parentId", readOnly = true)
    @GetMapping("/indexCategory2")
    public ResultVO queryCategory2(@RequestParam(value = "parentId") int parentId) {
        return indexCategoryService.queryCategory2(parentId);
    }

    @ApiOperation(value = "首页新品推荐接口")
    @GetMapping("/list-Recommends")
    public ResultVO listRecommendProducts() {
        return productService.listRecommendProducts();
    }

    @ApiOperation(value = "首页商品分类推荐信息接口")
    @GetMapping("/category_recommend")
    public ResultVO listRecommendProductByCategory() {
        return indexCategoryService.listFirstLevelCategories();
    }
}
